<template>
  <div>
    <div class="header">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="产品名称">
          <el-input
            v-model="formInline.user"
            placeholder="输入产品名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="添加时间">
          <el-date-picker
            v-model="formInline.region"
            type="date"
            placeholder="选择日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
      <div>
        <el-button type="warning" icon="el-icon-plus" @click="toProductPage"
          >添加商品</el-button
        >
        <el-button type="danger" icon="el-icon-delete">批量删除</el-button>
      </div>
    </div>
    <div class="content">
      <el-table :data="tableData" style="width: 100%" @select="selectHandle" @select-all="selectAll">
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column prop="date" label="日期" width="180" align="center">
        </el-table-column>
        <el-table-column prop="name" label="姓名" width="180" align="center">
        </el-table-column>
        <el-table-column prop="address" label="地址" align="center">
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
              >编辑</el-button
            >
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <Pagination />
    </div>
  </div>
</template>

<script>
import Pagination from "../../pagination/PaginationIndex.vue";
import moment from "moment";
// import {mapMutions} from 'vuex'
export default {
  components: {
    Pagination,
  },
  data() {
    return {
      formInline: {
        user: "",
        region: "",
      },
      tableData: [
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1517 弄",
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1519 弄",
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1516 弄",
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1517 弄",
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1519 弄",
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1516 弄",
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1517 弄",
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1519 弄",
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1516 弄",
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1517 弄",
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1519 弄",
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1516 弄",
        },
      ],
    };
  },
  methods: {
    // ...mapMutions('product',['changeRowData']),
    selectAll(e){
      console.log(e)
    this.$confirm('我测试一下能不能弹窗','提示',{
      confirmButtonText:'确定',
      cancelButtonText:'取消'
    })
      let arr=[]
      e.forEach(element => {
        arr.push(element.name)
      });
      console.log(arr)
    },
    selectHandle(e){
      console.log(e)
    },
    toProductPage() {
      this.$router.push("/product/add-product");
    },
    onSubmit() {
      console.log("submit!", this.formInline);
    },
    handleEdit(index, row) {
      console.log(index, row);
    
      this.$router.push('/product/add-product')
    },
    handleDelete(index, row) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
      console.log(index, row);
    },
  },
  created() {
    console.log(
      "获取当前时间",
      new Date(),
      moment().format("YYYY-MM-DD HH:mm:ss")
    );
  },
};
</script>

<style>
.header {
  background-color: white;
  padding-left: 10px;
  padding-top: 10px;
}
.content {
  background-color: white;
}
</style>